package main

import (
	"fmt"
)

func main() {
	mapDemo01()
}

func mapDemo01() {
	var address map[string]string //创建集合
	address = make(map[string]string)

	var school map[string]string = map[string]string{"zhangsan": "广州一中", "lisi": "广州二中"}
	address["zhansan"] = "北京"
	address["lisi"] = "广州"
	address["wangwu"] = "上海"

	printMap(address)
	printMap(school)
	printMap_01(school)

	/*判断元素是否存在*/
	addr, ok := address["lisi"]
	println(addr, ok)

	delete(address, "zhangsan")

	var res uint64 = factorial(uint64(10))
	fmt.Println(res)
}

/**
 *  根据key获取value
 */
func printMap(kv map[string]string) {

	for kvalue := range kv {
		fmt.Println(kvalue, kv[kvalue])
	}
}

/**
 *  打印key value
 */
func printMap_01(kv map[string]string) {
	for k, v := range kv {
		fmt.Println(k, v)
	}
}

/**
 * 递归函数
 */
func factorial(n uint64) (result uint64) {
	if n > 0 {
		result = n * factorial(n-1)
		return result
	}
	return 1
}
